//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussLobattoIntegral.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/Integrator.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (UInt64 maxIterations, Double absAccuracy, Microsoft::FSharp::Core::FSharpOption<Double>^ relAccuracy, Microsoft::FSharp::Core::FSharpOption<Boolean>^ useConvergenceEstimate) : CIntegrator(CGaussLobattoIntegral::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussLobattoIntegral = NULL;
#endif
        QuantLib::Size _maxIterations = (QuantLib::Size)ValueHelper::Convert (maxIterations);
        QuantLib::Real _absAccuracy = (QuantLib::Real)ValueHelper::Convert (absAccuracy);
        QuantLib::Real _relAccuracy = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (relAccuracy) ? (QuantLib::Real)ValueHelper::Convert (relAccuracy->Value) : Null<QuantLib::Real>()); //4
        bool _useConvergenceEstimate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (useConvergenceEstimate) ? (bool)ValueHelper::Convert (useConvergenceEstimate->Value) : true); //4
        _ppGaussLobattoIntegral = new boost::shared_ptr<QuantLib::GaussLobattoIntegral> (new QuantLib::GaussLobattoIntegral ( _maxIterations,  _absAccuracy,  _relAccuracy,  _useConvergenceEstimate ));
        SetIntegrator (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (boost::shared_ptr<QuantLib::GaussLobattoIntegral>& childNative, Object^ owner) : CIntegrator(CGaussLobattoIntegral::typeid)
{
#ifdef HANDLE
	_phGaussLobattoIntegral = NULL;
#endif
	_ppGaussLobattoIntegral = &childNative;
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
}
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (QuantLib::GaussLobattoIntegral& childNative, Object^ owner) : CIntegrator(CGaussLobattoIntegral::typeid)
{
#ifdef HANDLE
	_phGaussLobattoIntegral = NULL;
#endif
	_ppGaussLobattoIntegral = new boost::shared_ptr<QuantLib::GaussLobattoIntegral> (&childNative);
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
    _GaussLobattoIntegralOwner = owner;
    _IntegratorOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (CGaussLobattoIntegral^ copy) : CIntegrator(CGaussLobattoIntegral::typeid)
{
#ifdef HANDLE
	_phGaussLobattoIntegral = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussLobattoIntegral = new boost::shared_ptr<QuantLib::GaussLobattoIntegral> (copy->GetShared());
        _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
    }
}
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (System::Type^ t) : CIntegrator(CGaussLobattoIntegral::typeid)
{
#ifdef HANDLE
	_phGaussLobattoIntegral = NULL;
#endif
	if (!t->IsSubclassOf(CGaussLobattoIntegral::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (QuantLib::Handle<QuantLib::GaussLobattoIntegral>& childNative, Object^ owner)  : CIntegrator(CGaussLobattoIntegral::typeid)
{
	_phGaussLobattoIntegral = &childNative;
	_ppGaussLobattoIntegral = &static_cast<boost::shared_ptr<QuantLib::GaussLobattoIntegral>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
    _GaussLobattoIntegralOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (QuantLib::Handle<QuantLib::GaussLobattoIntegral> childNative)  : CIntegrator(CGaussLobattoIntegral::typeid)
{
	_phGaussLobattoIntegral = &childNative;
	_ppGaussLobattoIntegral = &static_cast<boost::shared_ptr<QuantLib::GaussLobattoIntegral>>(childNative.currentLink());
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::CGaussLobattoIntegral (QuantLib::GaussLobattoIntegral childNative)  : CIntegrator(CGaussLobattoIntegral::typeid)
{
#ifdef HANDLE
	_phGaussLobattoIntegral = NULL;
#endif
	_ppGaussLobattoIntegral = new boost::shared_ptr<QuantLib::GaussLobattoIntegral> (new QuantLib::GaussLobattoIntegral (childNative));
    _ppIntegrator = new boost::shared_ptr<QuantLib::Integrator> (boost::dynamic_pointer_cast<QuantLib::Integrator> (*_ppGaussLobattoIntegral));
}
#endif

Cephei::QL::Math::Integrals::CGaussLobattoIntegral::~CGaussLobattoIntegral ()
{
    if (_ppGaussLobattoIntegral != NULL)
    {
	    delete _ppGaussLobattoIntegral;
        _ppGaussLobattoIntegral = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussLobattoIntegral::!CGaussLobattoIntegral ()
{
    if (_ppGaussLobattoIntegral != NULL)
    {
	    delete _ppGaussLobattoIntegral;
    }
}
QuantLib::GaussLobattoIntegral& Cephei::QL::Math::Integrals::CGaussLobattoIntegral::GetReference ()
{
    if (_ppGaussLobattoIntegral == NULL) throw gcnew NativeNullException ();
	return **_ppGaussLobattoIntegral;
}
boost::shared_ptr<QuantLib::GaussLobattoIntegral>& Cephei::QL::Math::Integrals::CGaussLobattoIntegral::GetShared ()
{
    if (_ppGaussLobattoIntegral == NULL) throw gcnew NativeNullException ();
	return *_ppGaussLobattoIntegral;
}
QuantLib::GaussLobattoIntegral* Cephei::QL::Math::Integrals::CGaussLobattoIntegral::GetPointer ()
{
    if (_ppGaussLobattoIntegral == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussLobattoIntegral;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussLobattoIntegral>& Cephei::QL::Math::Integrals::CGaussLobattoIntegral::GetHandle ()
{
	if (_phGaussLobattoIntegral == NULL)
	{
		_phGaussLobattoIntegral = new Handle<QuantLib::GaussLobattoIntegral> (*_ppGaussLobattoIntegral);
	}
	return *_phGaussLobattoIntegral;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussLobattoIntegral::HasNative () 
{
	return (_ppGaussLobattoIntegral != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussLobattoIntegral^ Cephei::QL::Math::Integrals::CGaussLobattoIntegral_Factory::Create (UInt64 maxIterations, Double absAccuracy, Microsoft::FSharp::Core::FSharpOption<Double>^ relAccuracy, Microsoft::FSharp::Core::FSharpOption<Boolean>^ useConvergenceEstimate)
{
    return gcnew CGaussLobattoIntegral ( maxIterations,  absAccuracy,  relAccuracy,  useConvergenceEstimate);
}
